package com.zzw.dao;

import com.zzw.bean.Shipment;
import com.zzw.bean.ShipmentItem;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

public interface ShipmentMapper {
    // 新增发货单
    int insertShipment(Shipment shipment);

    // 批量新增发货明细
    int batchInsertShipmentItems(List<ShipmentItem> items);

    // 更新发货状态
    int updateShipmentStatus(@Param("id") Integer id, @Param("status") Integer status, @Param("shipTime") Date shipTime);

    // 根据ID查询发货单
    Shipment selectShipmentById(Integer id);

    // 根据订单ID查询发货单
    Shipment selectShipmentByOrderId(Integer orderId);

    // 查询发货单详情（包括发货明细）
    Shipment selectShipmentDetailById(Integer id);

    // 查询发货单列表
    List<Shipment> selectShipmentList(Shipment shipment);
    
    /**
     * 根据订单ID查询所有发货单
     */
    List<Shipment> selectShipmentsByOrderId(Integer orderId);
    
    /**
     * 根据订单ID查询发货单数量
     */
    int countShipmentsByOrderId(Integer orderId);
    
    /**
     * 根据订单ID查询所有已发货明细项
     */
    List<ShipmentItem> selectShippedItemsByOrderId(Integer orderId);
    
    /**
     * 根据订单ID查询已确认的发货明细，排除当前正在确认的发货单
     * @param orderId 订单ID
     * @param currentShipmentId 当前正在确认的发货单ID
     * @return 已确认的发货明细列表
     */
    List<ShipmentItem> selectConfirmedShippedItemsByOrderId(@Param("orderId") Integer orderId, @Param("currentShipmentId") Integer currentShipmentId);

    /**
     * 计算订单所有订单项的已发货数量总和
     * @param orderId 订单ID
     * @return 订单的总已发货数量
     */
    int sumOrderItemsShippedQuantity(Integer orderId);
}
